/*
 * @LastEditors: zhouyaxue
 * @Date: 2022-09-05 17:08:16
 * @LastEditTime: 2022-12-02 17:02:04
 */

// const modulesFiles = import.meta.globEager('.//*.ts')
const modulesFiles = import.meta.glob('./**/*.vue')
console.log('modulesFiles: ', modulesFiles);

const modules = Object.keys(modulesFiles).reduce(
  (modules: { [key: string]: any }, path: string) => {
    const moduleName = path.replace(/^\.\/modules\/(.*)\.\w+$/, '$1')
    modules[moduleName] = modulesFiles[path]?.default
    return modules
  },
  {}
)

console.log(modules, 'modules')

// const context = require.context('./', true, / *.vue$/);
// const mod = context.keys().reduce((modules: any, item) => {
//   const moduleName = item.replace(/^\.\/(.*)\.\w+$/, '$1');
//   const fileModule = context(item);
//   modules[moduleName] = fileModule.default;
//   return modules;
// }, {});

export default {
  install(app: any) {
    Object.entries(modules).forEach(([key, val]) => {
      app.component(key, val);
    });
  },
};
